package com.steven.im.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;
import com.steven.im.R;
import com.steven.im.base.BaseActivity;
import com.steven.im.base.Constant;
import com.steven.im.utils.ScreenUtil;
import com.steven.im.utils.TitleBuilder;

import butterknife.BindView;
import butterknife.OnClick;

public class IMAddFriendsActivity extends BaseActivity {
    @BindView(R.id.iv_title_right)
    ImageView ivTitleRight;

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {

    }

    @Override
    public int intiLayout() {
        return R.layout.activity_im_addfriends;
    }

    @Override
    public void initView() {
        ivTitleRight.setVisibility(View.GONE);
        new TitleBuilder(this).setTitleText(getString(R.string.addFriends))
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });

    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.ll_myQRCode, R.id.rl_scanToMyFriends, R.id.rl_phoneContacts,R.id.rl_searchFriends})
    public void onViewClicked(View view) {
        if (ScreenUtil.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.ll_myQRCode://我的二维码
                startActivity(new Intent(IMAddFriendsActivity.this, IMMyQRCodeActivity.class));
                break;
            case R.id.rl_scanToMyFriends://扫一扫成为我的好友
                new IntentIntegrator(this)
                        // 扫码的类型,条形码或者二维码
                        .setDesiredBarcodeFormats(IntentIntegrator.ALL_CODE_TYPES)
                        //这个参数可以设置也可以不设置，设置后使用自定义的二维码扫描框，不设置使用默认的
                        .setCaptureActivity(IMScanActivity.class)
                        .setRequestCode(Constant.QRCode)
                        // 设置提示语
                        .setPrompt("")
                        //设置使用那个摄像头
                        .setCameraId(0)
                        //是否在扫描完成后有提示音
                        .setBeepEnabled(true)
                        //扫完码之后生成二维码的图片
                        .setBarcodeImageEnabled(true)
                        //初始化扫描
                        .initiateScan();
                break;
            case R.id.rl_phoneContacts://手机联系人
                startActivity(new Intent(IMAddFriendsActivity.this, IMPhoneListActivity.class));
                break;
            case R.id.rl_searchFriends://扫一扫添加联系人
                startActivity(new Intent(IMAddFriendsActivity.this, IMSearchActivity.class));
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
        if (requestCode == Constant.QRCode) {
            if (result.getContents() != null) {
                startActivity(new Intent(IMAddFriendsActivity.this, IMUserInfoActivity.class));
            } else if (!Constant.isPhoto) {
                Toast.makeText(this, "scan error!", Toast.LENGTH_SHORT).show();
            }
        }
    }
}
